package com.ecar.api.service.driver.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ecar.api.service.driver.ComplaintService;
import com.ecar.api.support.util.UuidUtils;
import com.ecar.common.dto.DataBean;
import com.ecar.common.util.StringUtil;
import com.ecar.core.driver.dao.ComplaintMapper;
import com.ecar.core.driver.entity.Complaint;

import net.sf.json.JSONObject;

@Service
@Transactional
public class ComplaintServiceImpl implements ComplaintService{
	
	@Autowired
	ComplaintMapper complaintMapper;

	@Override
	public int deleteByPrimaryKey(String id) {
		// TODO Auto-generated method stub
		return complaintMapper.deleteByPrimaryKey(id);
	}

	@Override
	public DataBean insert(Complaint record) {
		record.setComplaintTime(new Date());
		int pk=complaintMapper.countByDriverId(record.getDriverId());
		if(pk>=3){
			return new DataBean(500,new JSONObject(),"申诉次数过多，申诉失败");
		}
		record.setId(UuidUtils.getUUID());
		int a=complaintMapper.insert(record);
		if(a<=0){
			return new DataBean(500,new JSONObject(),"申诉失败");
		}
		return new DataBean(200,new JSONObject(),"申诉成功");
	}

	@Override
	public int insertSelective(Complaint record) {
		// TODO Auto-generated method stub
		return complaintMapper.insertSelective(record);
	}

	@Override
	public Complaint selectByPrimaryKey(String id) {
		// TODO Auto-generated method stub
		return complaintMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Complaint record) {
		// TODO Auto-generated method stub
		return complaintMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Complaint record) {
		// TODO Auto-generated method stub
		return complaintMapper.updateByPrimaryKey(record);
	}
	
	
}
